<%@page import="com.spmanage.util.HttpUtil"%>
<%@page import="java.net.URLEncoder"%>
<%@page import="com.spmanage.util.BillingUtil"%><%@page import="com.spmanage.util.DbOperation"%>
<%@page import="com.spmanage.util.SqlUtil"%><%@page import="com.spmanage.util.WebAction"%>
<%@page import="com.spmanage.util.StringUtil"%><%@ page language="java" contentType="text/html; charset=UTF-8"
    pageEncoding="UTF-8"%><%
	WebAction webAction = new WebAction(request,response);
    
	System.out.println("网阔-IVR挂断参数："+request.getQueryString());
    
    String mobile = webAction.getParameterString("caller");		//用户手机号
    String callno = webAction.getParameterString("called");		//拨打号码
    int fee = webAction.getParameterInt("FeeRate");					//资费
    String calltime = webAction.getParameterString("begintime");	//拨打时间
    String halttime = webAction.getParameterString("endtime");	//挂断时间
    int feeseconds = webAction.getParameterInt("dur");			//拨打时长
    
    if(mobile==null){
    	response.getWriter().write("err");
    }else{
    	response.getWriter().write("ok");
        int shichang = 0;        //时长，秒
        //时长，截取最后4位，算出多少秒
        shichang = Integer.parseInt(halttime.substring(10,14))-Integer.parseInt(calltime.substring(10,14));
        
        //参数修改格式
        if(calltime!=null){
        	calltime = calltime.substring(0,4)+"-"+calltime.substring(4,6)+"-"+calltime.substring(6,8)+" "+calltime.substring(8,10)+":"+calltime.substring(10,12)+":"+calltime.substring(12,14);
        }
        if(halttime!=null){
        	halttime = halttime.substring(0,4)+"-"+halttime.substring(4,6)+"-"+halttime.substring(6,8)+" "+halttime.substring(8,10)+":"+halttime.substring(10,12)+":"+halttime.substring(12,14);
        }
        //最后赋值给feeseconds,以便后面的操作，这个精确到秒的
        feeseconds = shichang;
        
        
        StringBuilder getChannelIdSql = new StringBuilder("select cpid from adminspcp where spcommand = '");
        getChannelIdSql.append(callno);
        getChannelIdSql.append("'");
        int channel =SqlUtil.getIntResult(getChannelIdSql.toString(),5) ;
        int ischeck = BillingUtil.getIvrCheckCall(channel);
        
        int provinceId = BillingUtil.getProvinceId(mobile);
        

        
        String spId="";//spid：30,后期还能会变成动态的
       	if(callno.equals("1259025217")){
       		spId="30";
       	}
       	else if(callno.equals("1259025212")){
       		spId="131";
       	}
       	else if(callno.equals("1259025372")){
       		spId="132";
       	}
    	//1259025212，1259025372
        //------------------------------------------------------
        if(ischeck==0){//0为不扣量，1为扣量
    		//合作方url
    		String url="";
    		if(callno.equals("1259025217")||callno.equals("1259025212")){
    			//channel="10063";
    			url="http://las.energysh.com.cn/las2/logs.htm";
    			url=url+"?ani="+mobile+"&dnis="+callno+"&stime="+URLEncoder.encode(calltime,"UTF-8")+"&etime="+URLEncoder.encode(halttime,"UTF-8")+"&seclen="+feeseconds+"&fee="+fee;;
    			System.out.println("网阔-艾麒-IVR同步:"+url);
    			HttpUtil.getHtmlSource(url,"UTF-8");
    		}
    	
    		//-------------------------------------------------------
        }
    	//保存到ivr天表
        StringBuilder conditionSql = new StringBuilder();
        conditionSql.append("'");
        conditionSql.append(spId);
        conditionSql.append("','");
        conditionSql.append(channel);//渠道号,后期还能会变成动态的
        conditionSql.append("','");
        conditionSql.append(provinceId);//省份ID
        conditionSql.append("','");
        conditionSql.append(mobile);//手机号
        conditionSql.append("','");
        conditionSql.append(callno);
        conditionSql.append("','");
        conditionSql.append(fee);
        conditionSql.append("','");
        conditionSql.append("");
        conditionSql.append("','");
        conditionSql.append(calltime);
        conditionSql.append("','");
        conditionSql.append(halttime);
        conditionSql.append("','");
        conditionSql.append(feeseconds);
        conditionSql.append("','");
        conditionSql.append(ischeck);
        conditionSql.append("',");
        conditionSql.append("getDate()");
        System.out.println(conditionSql.toString());
        SqlUtil.executeUpdate("insert into  "+BillingUtil.getIvrHaltDay()+"(areaid,channel,province,mobile,callno,fee,carrier,calltime,halttime,feeseconds,ischeck,createdtime) values("+conditionSql.toString()+")",DbOperation.DB_STAT);

    }

%>
